package ModelLayer;
import java.util.ArrayList;

/**
 * Vestbjerg project
 * @GroupB2 (UCN - Computer Science DMAJ0914) 
 */
public class PurchaseContainer
{
    // instance variables
    private static PurchaseContainer instance;
    private ArrayList<Purchase> purchaseList;

    /**
     * Constructor for objects of class PurchaseContainer
     */
    private PurchaseContainer()
    {
        purchaseList = new ArrayList<Purchase>();
    }

    public static PurchaseContainer getInstance()
    {
        if(instance == null)
        {
            instance = new PurchaseContainer();
        }
        return instance;
    }

    public void addPurchase(Purchase purchase) 
    {
        if(!purchaseList.contains(purchase)) {
            purchaseList.add(purchase);
        } 
    }

    public Purchase findPurchase(String id) 
    {
        Purchase returnPurchase = null;
        for(Purchase purchase : purchaseList) 
        {

            if(id.equals(purchase.getId())) 
            {
                returnPurchase = purchase;
            }
        }
        return returnPurchase;
    }

    public void deletePurchase(Purchase purchase) 
    {
        if(purchaseList.contains(purchase)) 
        {
            purchaseList.remove(purchase);
        }
    }
    
    public ArrayList<Purchase> getPurchaseList() 
    {
     return purchaseList;
    }
}
